﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using Pg.BioMedics.SDR.Services;

namespace Pg.BioMedics.SDR.Web.Modules
{
    /// <summary>
    /// A HTTP module utilized to manage observer service lifecycle
    /// </summary>
    public class ObserverHostingModule : IHttpModule
    {
        #region Fields

        private IObserverService observerService;

        #endregion

        #region IHttpModule Members

        public void Init(HttpApplication context)
        {
            // attach observer
            this.observerService = ServiceFactory.ObserverService;
            this.observerService.Attach();
        }

        public void Dispose()
        {
            // detach observer
            if (this.observerService != null)
            {
                this.observerService.Detach();
                this.observerService = null;
            }
        }

        #endregion
    }
}
